﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VideoClubGorbea.Infraestructure.DomainBase
{
    public abstract class EntityBase
    {
        private object key;

        public EntityBase() : this(null)
        {

        }
        public EntityBase(object key)
        {
            this.key = key;
        }

        public object Key
        {
            get
            {
                return this.key;
            }
        }

        public override bool Equals(object entity)
        {
            if ((entity ==null) || !(entity is EntityBase))
            {
                return false;
            }
            else
	        {
                return (this == (EntityBase)entity);
	        }
        }

        public static bool operator ==(EntityBase base1, EntityBase base2)
        {
            if (((object)base1 == null) && ((object)base2 == null))
            {
                return true;
            }

            if (((object)base1 == null) || ((object)base2 == null))
            {
                return false;
            }

            if (base1.Key != base2.Key)
            {
                return false;
            }

            return true;
        }
        public static bool operator !=(EntityBase base1, EntityBase base2)
        {
            return !(base1 == base2);
        }

        public override int GetHashCode()
        {
            return this.Key.GetHashCode();
        }

    }
}
